
package com.ken.work.mvc.controller.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ken.work.mvc.annotation.MyController;
import com.ken.work.mvc.annotation.MyRequestMapping;
import com.ken.work.mvc.annotation.RequestType;
import com.ken.work.mvc.controller.MyBaseController;
import com.ken.work.mvc.entity.JumpObj;
import com.ken.work.mvc.entity.JumpType;
import com.ken.work.mvc.entity.User;
/*
 * @author ken
 * 2017-02-16
 * 用户登陆及注册控制器
 */
@MyController
@MyRequestMapping(value = "/login")
public class LoginController extends MyBaseController{
	@Override
	public void setHttpServlet(HttpServletRequest request,HttpServletResponse response){
		this.request=request;
		this.response=response;
	}
	 
	@MyRequestMapping(value = "/list",requestType=RequestType.GET)
	public JumpObj index()
	{
		User user=new User("admin","1234");
		JumpObj obj=new JumpObj();
		String outHtml=getGsonStr(user);
		obj.setForWordType(JumpType.JSON);
		obj.setOutHtml(outHtml);
		return obj;
	}
	@MyRequestMapping(value = "/checkUser",requestType=RequestType.POST)
	public JumpObj loginCheck()
	{
		User user=GetParamObj(User.class);
		JumpObj obj=new JumpObj();
		if("admin".equals(user.getUserName())&&"1234".equals(user.getPassword())){
			obj.setForWordType(JumpType.DEFAULT);
			obj.setForWord_Url("/WEB-INF/login/welcome.jsp");
			obj.setMesg("登陆成功!");
		}else {
			obj.setForWordType(JumpType.DEFAULT);
			obj.setForWord_Url("/WEB-INF/login/failure.jsp");
			obj.setMesg("登陆失败!请核对用户名和密码!");
		}
		request.setAttribute("userName", user.getUserName());
		return obj;
	}
	 
}
